#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
map<string,int> a;
string t[1005],s[1005],ans[1005];
bool dui(string x)
{
	int cnt = 0;
	long long a=0;
	bool flag = false;
	int i = 0;
	if(x[i] == '0')
	flag = true;
	for(i;i < x.size();i++)
	{
		if(x[i] == '.'|| x[i] == ':')
		break;
		a = a*10 + (x[i]-'0');
	}
	for(i;i < x.size();i++)
	{
		if(x[i] == '.'||x[i] == ':')
		cnt++;
		else
		break;
	}
	if(flag == true&&a != 0)
	return false;
	if(a > 255)
	return false;
	flag = false;
	a=0;
	if(x[i] == '0')
	flag = true;
	for(i;i < x.size();i++)
	{
		if(x[i] == '.'|| x[i] == ':')
		break;
		a = a*10 + (x[i]-'0');
	}
	for(i;i < x.size();i++)
	{
		if(x[i] == '.'||x[i] == ':')
		cnt++;
		else
		break;
	}
	if(flag == true&&a != 0)
	return false;
	if(a > 255)
	return false;
	flag = false;
	a=0;
	if(x[i] == '0')
	flag = true;
	for(i;i < x.size();i++)
	{
		if(x[i] == '.'|| x[i] == ':')
		break;
		a = a*10 + (x[i]-'0');
	}
	for(i;i < x.size();i++)
	{
		if(x[i] == '.'||x[i] == ':')
		cnt++;
		else
		break;
	}
	if(flag == true&&a != 0)
	return false;
	if(a > 255)
	return false;
	flag = false;
	a=0;
	if(x[i] == '0')
	flag = true;
	for(i;i < x.size();i++)
	{
		if(x[i] == '.'|| x[i] == ':')
		break;
		a = a*10 + (x[i]-'0');
	}
	for(i;i < x.size();i++)
	{
		if(x[i] == '.'||x[i] == ':')
		cnt++;
		else
		break;
	}
	if(flag == true&&a != 0)
	return false;
	if(a > 255)
	return false;
	flag = false;
	a=0;
	if(x[i] == '0')
	flag = true;
	for(i;i < x.size();i++)
	{
		if(x[i] == '.'|| x[i] == ':')
		break;
		a = a*10 + (x[i]-'0');
	}
	for(i;i < x.size();i++)
	{
		if(x[i] == ':')
		cnt++;
		else
		break;
	}
	if(flag == true&&a != 0)
	return false;
	if(a > 65535)
	return false;
	if(cnt != 4)
	return false;
	return true;
} 
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	int n;
	cin >> n; 
	for(int i = 1;i <= n;i++)
	{
		cin >> t[i] >> s[i];
		if(!dui(s[i])) 
		{
			cout << "ERR" << endl;
			continue;
		}
		if(t[i] == "Server")
		{
			if(a[s[i]] != 0)
			{
				cout << "FAIL" << endl; 
			}
			else
			{
				a[s[i]] = i;
				cout << "OK" << endl; 
			} 
		}
		else
		{
			if(a[s[i]] != 0)
			cout << a[s[i]] << endl;
			else
			cout << "FAIL" << endl;
		}
	}
	return 0;
}
